package com.xuecheng.controller;

import com.xuecheng.dto.AddCourseDTO;
import com.xuecheng.dto.EditCourseDTO;
import com.xuecheng.dto.QueryCourseParamsDTO;
import com.xuecheng.handler.GradedVerificationGroups;
import com.xuecheng.model.PageParams;
import com.xuecheng.model.PageResult;
import com.xuecheng.po.CourseBase;
import com.xuecheng.service.CourseBaseInfoService;
import com.xuecheng.vo.CourseBaseInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 课程基本信息
 */
@Slf4j
@Api(value = "课程基本信息", tags = "课程管理")
@RestController("CourseBaseController")
@RequestMapping("/course")
public class CourseBaseInfoController {
	
	@Resource
	private CourseBaseInfoService courseBaseInfoService;
	
	/**
	 * 课程管理接口-分页查询
	 */
	@GetMapping("/list")
	@ApiOperation("分页查询")
	public PageResult<CourseBase> getPageParamsList(PageParams params,QueryCourseParamsDTO queryCourseParamsDTO) {
		log.info("分页查询,params:{},queryCourseParamsDTO:{}", params,queryCourseParamsDTO);
		return courseBaseInfoService.queryCourseBaseList(params,queryCourseParamsDTO);
	}
	
	/**
	 * 添加课程
	 */
	@PostMapping
	@ApiOperation("添加课程")
	public CourseBaseInfoVO addCourseBase(@RequestBody @Validated({GradedVerificationGroups.Inster.class}) AddCourseDTO addCourseDTO) {
		Long id = 1232141425L;
		log.info("id：{}，添加课程：{}", id, addCourseDTO);
		return courseBaseInfoService.createCourseBase(id, addCourseDTO);
	}
	
	/**
	 * 根据id查询课程基本信息
	 */
	@GetMapping("/{id}")
	@ApiOperation("根据id查询")
	public CourseBaseInfoVO getCourseBaseById(@PathVariable Long id) {
		log.info("根据id查询：{}", id);
		return courseBaseInfoService.getCourseBaseInfo(id);
	}
	
	/**
	 * 修改课程
	 */
	@PutMapping
	@ApiOperation("修改课程")
	public CourseBaseInfoVO updateCourseBase(@RequestBody @Validated({GradedVerificationGroups.Update.class}
	) EditCourseDTO editCourseDTO) {
		Long id = 1232141425L;
		log.info("id：{}，修改课程：{}", id, editCourseDTO);
		return courseBaseInfoService.updateCourseBase(id, editCourseDTO);
	}
	
	/**
	 * 删除课程
	 */
	@DeleteMapping("/{id}")
	@ApiOperation("删除课程")
	public void deleteCourseBase(@PathVariable Long id) {
		log.info("删除课程id：{}", id);
		courseBaseInfoService.removeById(id);
	}
	
}
